package com.li.springbootproject.spring.beaninit;

import com.lidong.toolkit.constant.LogConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 3/12/2022 4:22 PM
 */
public class InitializingBeanExample implements InitializingBean {

    private static final Logger logger = LoggerFactory.getLogger(InitializingBeanExample.class);

    private int id;

    private String name;

    @Override
    public void afterPropertiesSet() {
        logger.info(LogConst.LOG_SUCCESS_PREFIX + " 初始化前的值为：{}", this);
        logger.info(LogConst.LOG_SUCCESS_PREFIX + " 我要对 PeopleBean 进行初始化！");
        this.id = 100;
        this.name = "李四";
        logger.info(LogConst.LOG_SUCCESS_PREFIX + " 初始化后的值为：{}", this);
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "PeopleBean{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

}
